import userTempId from "@/utils/userTempId";
import { getItem, setItem } from "@/utils/localStorage";
import { reqLogin } from "@/api";
const state = {
  userTempId:userTempId(),
  token:getItem('token') || ""
}
const actions = {
  async getToken({ commit }, userInfo) {
    const result = await reqLogin(userInfo);
    commit("set_Token", { token: result.token });
  },
};
const getters = {};
const mutations = {
  //设置token
  set_Token(state,payload){
    state.token = payload.token;
    //永久化存储token
    setItem("token",payload.token)
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
}
